
#ifndef TP_DISPLAY_H
#define TP_DISPLAY_H

#include "tp_bitmap.h"

TP_DECL_BEGIN

struct _TpDisplay;
typedef struct _TpDisplay TpDisplay;

typedef int (*TpDisplayUpdate)(TpDisplay* thiz, int xo, int yo, TpBitmap* bitmap, TpRect* rect);
typedef int (*TpDisplayWidth)(TpDisplay* thiz);
typedef int (*TpDisplayHeight)(TpDisplay* thiz);
typedef void (*TpDisplayDestroy)(TpDisplay* thiz);

struct _TpDisplay{
	TpDisplayUpdate update;
	TpDisplayWidth width;
	TpDisplayHeight height;
	TpDisplayDestroy destroy;

	char priv[1];
};

/*
	用bitmap中rect指定的区域更新display，display中更新起始位置由xo/yo指定
*/
static inline int tp_display_update(TpDisplay* thiz, int xo, int yo, TpBitmap* bitmap, TpRect* rect)
{
	if (NULL == thiz || NULL == bitmap) return TP_RET_FAIL;

	return thiz->update(thiz, xo, yo, bitmap, rect);
}

static inline int tp_display_width(TpDisplay* thiz)
{
	if(NULL == thiz || NULL == thiz->width) return TP_RET_FAIL;

	return thiz->width(thiz);
}

static inline int tp_display_height(TpDisplay* thiz)
{
	if(NULL == thiz || NULL == thiz->height) return TP_RET_FAIL;

	return thiz->height(thiz);
}

static inline void tp_display_destroy(TpDisplay* thiz)
{
	if (NULL != thiz && NULL != thiz->destroy)
	{
		thiz->destroy(thiz);
	}

	return;
}

TP_DECL_END

#endif /*TP_DISPLAY_H*/